<template>
    <div>
        <h1>会员新增</h1>
        <table class="table">
            <tr>
                <td>name</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>password</td>
                <td><input type="password" v-model="data.password"></td>
            </tr>
            <tr>
                <td>houbbyString</td>
                <td><input type="checkbox" name="" id="">游戏
                    <input type="checkbox" name="" id="">游泳
                    <input type="checkbox" name="" id="">打篮球
                    <input type="checkbox" name="" id="">跑步
                </td>
            </tr>
            <tr>
                <td>img</td>
                <td></td>
            </tr>
            <tr>
                <td>memberLevelId</td>
                <td><select v-model="data.memberLevelId">
                    <option value="0">请选择会员等级</option>
                    <option v-for="d in leveldata":value="d.id">{{d.name}}</option>
                    
                </select></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="button" value="保存" class="btn btn-success" @click="saveinfo" >
                    <a href="/">返回</a>
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
    import axios from 'axios';
    import{ ref, onMounted} from 'vue';
    import{useRouter} from 'vue-router';
    const router=useRouter();
    const data=ref({
        "id": 0,
        "name": "小明",
        "password": "123456",
        "houbbyCount": 0,
        "houbbyString": "string",
        "isDelete": true,
        "img": "string",
        "memberLevelId": 0
    })
    const saveinfo=()=>{
        axios.post("https://localhost:7096/api/Member/AddMember",data.value).then(res=>{
            if(res.data>0){
                alert('新增成功');
                router.push({path:'/'})
            }else{
                alert('新增失败了。。。。')
            }
        })

    }
    onMounted(()=>{
        getleveldata()
    })
    const leveldata=ref([])
    const getleveldata=()=>{
        axios.get("https://localhost:7096/api/MemberLevel/GetAll").then(res=>{
            leveldata.value=res.data;
        })
    }
</script>

<style scoped>

</style>